
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 10/08/2013 22:09:27
-- Generated from EDMX file: C:\Users\kendell\Documents\Visual Studio 2012\Projects\StationaryRequest\StationaryRequest\StationaryRequest.DAL\InventoryModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [InventoryDB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_StationaryCategoryStationaryItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[StationaryItems] DROP CONSTRAINT [FK_StationaryCategoryStationaryItem];
GO
IF OBJECT_ID(N'[dbo].[FK_StationaryTypeStationaryItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[StationaryItems] DROP CONSTRAINT [FK_StationaryTypeStationaryItem];
GO
IF OBJECT_ID(N'[dbo].[FK_InvoiceOrder]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Orders] DROP CONSTRAINT [FK_InvoiceOrder];
GO
IF OBJECT_ID(N'[dbo].[FK_OrderStationaryItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[StationaryItems] DROP CONSTRAINT [FK_OrderStationaryItem];
GO
IF OBJECT_ID(N'[dbo].[FK_SupplierInvoice]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Invoices] DROP CONSTRAINT [FK_SupplierInvoice];
GO
IF OBJECT_ID(N'[dbo].[FK_ShoppingCartStationaryRequest]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[StationaryRequests] DROP CONSTRAINT [FK_ShoppingCartStationaryRequest];
GO
IF OBJECT_ID(N'[dbo].[FK_StationaryItemStationaryRequest]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[StationaryRequests] DROP CONSTRAINT [FK_StationaryItemStationaryRequest];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[StationaryCategories]', 'U') IS NOT NULL
    DROP TABLE [dbo].[StationaryCategories];
GO
IF OBJECT_ID(N'[dbo].[StationaryItems]', 'U') IS NOT NULL
    DROP TABLE [dbo].[StationaryItems];
GO
IF OBJECT_ID(N'[dbo].[StationaryTypes]', 'U') IS NOT NULL
    DROP TABLE [dbo].[StationaryTypes];
GO
IF OBJECT_ID(N'[dbo].[Orders]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Orders];
GO
IF OBJECT_ID(N'[dbo].[Suppliers]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Suppliers];
GO
IF OBJECT_ID(N'[dbo].[Invoices]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Invoices];
GO
IF OBJECT_ID(N'[dbo].[ShoppingCarts]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ShoppingCarts];
GO
IF OBJECT_ID(N'[dbo].[StationaryRequests]', 'U') IS NOT NULL
    DROP TABLE [dbo].[StationaryRequests];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'StationaryCategories'
CREATE TABLE [dbo].[StationaryCategories] (
    [Name] nvarchar(300)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'StationaryItems'
CREATE TABLE [dbo].[StationaryItems] (
    [Name] nvarchar(300)  NOT NULL,
    [StationaryCategoryName] nvarchar(300)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [StationaryTypeName] nvarchar(300)  NOT NULL,
    [OrderId] int  NOT NULL
);
GO

-- Creating table 'StationaryTypes'
CREATE TABLE [dbo].[StationaryTypes] (
    [Name] nvarchar(300)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Orders'
CREATE TABLE [dbo].[Orders] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Quantity] nvarchar(max)  NOT NULL,
    [UnitCost] nvarchar(max)  NOT NULL,
    [InvoiceId] int  NOT NULL
);
GO

-- Creating table 'Suppliers'
CREATE TABLE [dbo].[Suppliers] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Address] nvarchar(max)  NOT NULL,
    [Telephone] nvarchar(max)  NOT NULL,
    [Fax] nvarchar(max)  NOT NULL,
    [Salesman] nvarchar(max)  NOT NULL,
    [Email] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Invoices'
CREATE TABLE [dbo].[Invoices] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [SupplierId] int  NOT NULL
);
GO

-- Creating table 'ShoppingCarts'
CREATE TABLE [dbo].[ShoppingCarts] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [UserName] nvarchar(max)  NOT NULL,
    [RequestDate] datetime  NOT NULL
);
GO

-- Creating table 'StationaryRequests'
CREATE TABLE [dbo].[StationaryRequests] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [StationaryItemName] nvarchar(300)  NOT NULL,
    [ShoppingCartId] int  NOT NULL,
    [Quantity] nvarchar(max)  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Name] in table 'StationaryCategories'
ALTER TABLE [dbo].[StationaryCategories]
ADD CONSTRAINT [PK_StationaryCategories]
    PRIMARY KEY CLUSTERED ([Name] ASC);
GO

-- Creating primary key on [Name] in table 'StationaryItems'
ALTER TABLE [dbo].[StationaryItems]
ADD CONSTRAINT [PK_StationaryItems]
    PRIMARY KEY CLUSTERED ([Name] ASC);
GO

-- Creating primary key on [Name] in table 'StationaryTypes'
ALTER TABLE [dbo].[StationaryTypes]
ADD CONSTRAINT [PK_StationaryTypes]
    PRIMARY KEY CLUSTERED ([Name] ASC);
GO

-- Creating primary key on [Id] in table 'Orders'
ALTER TABLE [dbo].[Orders]
ADD CONSTRAINT [PK_Orders]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Suppliers'
ALTER TABLE [dbo].[Suppliers]
ADD CONSTRAINT [PK_Suppliers]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Invoices'
ALTER TABLE [dbo].[Invoices]
ADD CONSTRAINT [PK_Invoices]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ShoppingCarts'
ALTER TABLE [dbo].[ShoppingCarts]
ADD CONSTRAINT [PK_ShoppingCarts]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'StationaryRequests'
ALTER TABLE [dbo].[StationaryRequests]
ADD CONSTRAINT [PK_StationaryRequests]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [StationaryCategoryName] in table 'StationaryItems'
ALTER TABLE [dbo].[StationaryItems]
ADD CONSTRAINT [FK_StationaryCategoryStationaryItem]
    FOREIGN KEY ([StationaryCategoryName])
    REFERENCES [dbo].[StationaryCategories]
        ([Name])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_StationaryCategoryStationaryItem'
CREATE INDEX [IX_FK_StationaryCategoryStationaryItem]
ON [dbo].[StationaryItems]
    ([StationaryCategoryName]);
GO

-- Creating foreign key on [StationaryTypeName] in table 'StationaryItems'
ALTER TABLE [dbo].[StationaryItems]
ADD CONSTRAINT [FK_StationaryTypeStationaryItem]
    FOREIGN KEY ([StationaryTypeName])
    REFERENCES [dbo].[StationaryTypes]
        ([Name])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_StationaryTypeStationaryItem'
CREATE INDEX [IX_FK_StationaryTypeStationaryItem]
ON [dbo].[StationaryItems]
    ([StationaryTypeName]);
GO

-- Creating foreign key on [InvoiceId] in table 'Orders'
ALTER TABLE [dbo].[Orders]
ADD CONSTRAINT [FK_InvoiceOrder]
    FOREIGN KEY ([InvoiceId])
    REFERENCES [dbo].[Invoices]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_InvoiceOrder'
CREATE INDEX [IX_FK_InvoiceOrder]
ON [dbo].[Orders]
    ([InvoiceId]);
GO

-- Creating foreign key on [OrderId] in table 'StationaryItems'
ALTER TABLE [dbo].[StationaryItems]
ADD CONSTRAINT [FK_OrderStationaryItem]
    FOREIGN KEY ([OrderId])
    REFERENCES [dbo].[Orders]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderStationaryItem'
CREATE INDEX [IX_FK_OrderStationaryItem]
ON [dbo].[StationaryItems]
    ([OrderId]);
GO

-- Creating foreign key on [SupplierId] in table 'Invoices'
ALTER TABLE [dbo].[Invoices]
ADD CONSTRAINT [FK_SupplierInvoice]
    FOREIGN KEY ([SupplierId])
    REFERENCES [dbo].[Suppliers]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SupplierInvoice'
CREATE INDEX [IX_FK_SupplierInvoice]
ON [dbo].[Invoices]
    ([SupplierId]);
GO

-- Creating foreign key on [ShoppingCartId] in table 'StationaryRequests'
ALTER TABLE [dbo].[StationaryRequests]
ADD CONSTRAINT [FK_ShoppingCartStationaryRequest]
    FOREIGN KEY ([ShoppingCartId])
    REFERENCES [dbo].[ShoppingCarts]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ShoppingCartStationaryRequest'
CREATE INDEX [IX_FK_ShoppingCartStationaryRequest]
ON [dbo].[StationaryRequests]
    ([ShoppingCartId]);
GO

-- Creating foreign key on [StationaryItemName] in table 'StationaryRequests'
ALTER TABLE [dbo].[StationaryRequests]
ADD CONSTRAINT [FK_StationaryItemStationaryRequest]
    FOREIGN KEY ([StationaryItemName])
    REFERENCES [dbo].[StationaryItems]
        ([Name])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_StationaryItemStationaryRequest'
CREATE INDEX [IX_FK_StationaryItemStationaryRequest]
ON [dbo].[StationaryRequests]
    ([StationaryItemName]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------